import logger from '../../core/logger';
import utils from '../../core/utils';

export default class dashModel {
  format: string;
  accept_description: Array<string>;
  accept_quality: Array<number>;
  timelength: number;
  video_codecid: number;
  dash: dashInfoModel;
}

export class dashInfoModel {
  duration: number;
  video: Array<dashItem>;
  audio: Array<dashItem>;
}

export class dashItem {
  baseUrl: string;
  base_Url: string;
  bandwidth: string;
  codecs: string;
  codecid: number;
  frameRate: string;
  frame_Rate: string;
  height: string;
  width: string;
  id: number;
  sar: string;
  mimeType: string;
  mime_Type: string;
  startWithSap: number;
  segmentBase: segmentBase;
  segment_Base: segmentBase;

  get fps() {
    try {
      if (!utils.isEmpty(this.frameRate)) {
        let values = this.frameRate.split('/');
        if (values.length == 1)
          return this.frameRate;
        return (parseFloat(values[0]) / parseFloat(values[1])).toString(1);
      }
      else if (!utils.isEmpty(this.frame_Rate)) {
        let values = this.frame_Rate.split('/');
        if (values.length == 1)
          return this.frame_Rate;
        return (parseFloat(values[0]) / parseFloat(values[1])).toString(1);
      }
    }
    catch (e) {
      logger.error(e);
    }
    return "0";
  }
}

export class segmentBase {
  initialization: string;
  indexRange: string;
  index_Range: string;
}